package com.osmino.contacts.view.style.tools;

import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.osmino.contacts.view.style.StyleAttribute;

public class Tools{
	
	private static final boolean DBG = true;
	
	public static void applyViewAttribute(View root, StyleAttribute attribute){
		if(DBG){
			System.out.println("id"+attribute.getViewId());
			System.out.println("type"+attribute.getTypeOfView());
			System.out.println("att"+attribute.getAttribute());
			System.out.println("val"+attribute.getValue());
		}
		if(!attribute.isValid()){
			throw new IllegalStateException("!attribute.isValid()");
		}
		int id = attribute.getViewId();
		int type = attribute.getTypeOfView();
		int att = attribute.getAttribute();
		int val = attribute.getValue();
		switch(att){
		case StyleAttribute.ATT_IMAGE_BUTTON_BACKGROUND:
			((ImageButton)root.findViewById(id)).setBackgroundResource(val);
			break;
		case StyleAttribute.ATT_IMAGE_BUTTON_FOREGROUND:
			((ImageButton)root.findViewById(id)).setImageResource(val);
			break;
		case StyleAttribute.ATT_IMAGE_VIEW_BACKGROUND:
			((ImageView)root.findViewById(id)).setBackgroundResource(val);
			break;
		case StyleAttribute.ATT_IMAGE_VIEW_FOREGROUND:
			((ImageView)root.findViewById(id)).setImageResource(val);
			break;
		case StyleAttribute.ATT_TEXT_VIEW_BACKGROUND:
			((TextView)root.findViewById(id)).setBackgroundResource(val);
			break;
		case StyleAttribute.ATT_TEXT_VIEW_TEXT_COLOR:
			((TextView)root.findViewById(id)).setTextColor(val);
			break;
		case StyleAttribute.ATT_TEXT_VIEW_TEXT_SIZE:
			((TextView)root.findViewById(id)).setTextSize(val);
			break;
		}
	}
}